from django.http import JsonResponse

def login_required(view):
    def wrapper(request,*args,**kwargs):
        if not request.user.is_authenticated:
            return JsonResponse({
                'code':400,
                'errmsg':'未登录!'
            })
        return view(request,*args,**kwargs)
    return wrapper

class LoginRequiredMixin(object):
    @classmethod
    def as_view(cls,*args,**kwargs):
        view = super().as_view(*args,**kwargs)
        view = login_required(view)
        return view